using System;
using System.Reflection;
using System.IO;

namespace Pegasus.Diagnostics.Telnet
{
	/// <summary>
	/// Implements the Version command for the telnet service
	/// </summary>
	public class CommandVersion : ITelnetCommand
	{
		/// <summary>
		/// Default Constructor
		/// </summary>
		public CommandVersion()
		{
		}

		/// <summary>
		/// The names of the command that the user types in.
		/// </summary>
		public string Command
		{
			get
			{
				return "version";
			}
		}

		/// <summary>
		/// Return that there are no short cut commands or key 
		/// </summary>
		public string[] CommandShortCuts
		{
			get
			{
				return null;
			}
		}

		/// <summary>
		/// Execute the command.
		/// </summary>
		/// <param name="writer">Text stream to write to</param>
		/// <param name="args">Additional parameters that the user typed in.</param>
		public void ExecCommand( TextWriter writer, string[] args )
		{
			Assembly exeAsm = Assembly.GetEntryAssembly();
			if( exeAsm != null )
			{
				writer.WriteLine( "Execution Assembly" );
				writer.WriteLine( "  {0}", exeAsm.FullName );
				writer.WriteLine();
			}

			Assembly entryAsm = Assembly.GetEntryAssembly();
			if( entryAsm != null )
			{
				writer.WriteLine( "Entry Assembly" );
				writer.WriteLine( "  {0}", entryAsm.FullName );
				writer.WriteLine();
			}

			writer.WriteLine( "Support Assemblies" );
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			
			if( assemblies.Length > 0 )
			{
				foreach( Assembly asm in assemblies )
				{
					writer.WriteLine( "  {0}", asm.FullName );
				}
			}
			else
			{
				writer.WriteLine( "  No support assemblies loaded" );
			}
		}

		/// <summary>
		/// Show a single line of help about the command
		/// </summary>
		/// <returns>Single line brief description of command</returns>
		public string GetHelp()
		{
			return "Show the assembly version inforamtion";
		}

		/// <summary>
		/// Show a the full usage help about the command
		/// </summary>
		/// <param name="writer">Text stream to write to</param>
		public void ShowDetailedHelp( TextWriter writer )
		{
			writer.WriteLine( "Command: version" );
			writer.WriteLine( "Usage: version" );
			writer.WriteLine();
			writer.WriteLine( "Description:  Show the assembly version inforamtion" );
		}
	}
}
